package yanyan.com.tochar.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import yanyan.com.tochar.R;
import yanyan.com.tochar.beans.HomeListBean;

public class CommonListAdapter extends BaseAdapter {
    private List<HomeListBean> listBeans;
   private LayoutInflater inflater;

    public CommonListAdapter(Context context, List<HomeListBean> listBeans) {
        this.listBeans = listBeans;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return listBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null)
        {
            convertView=inflater.inflate(R.layout.item_common_list,null);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.common_list_image);
            TextView title= (TextView) convertView.findViewById(R.id.common_list_title);
            TextView text= (TextView) convertView.findViewById(R.id.common_list_text);
            HomeListBean listBean = listBeans.get(position);
            imageView.setImageResource(listBean.getImage());
            title.setText(listBean.getTitle());
            text.setText(listBean.getText());
        }
        return convertView;
    }
}
